package com.pucheng.bracelet.app.dispatcher;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.LogUtils;
import com.pucheng.bracelet.R;


public class RunCountTimer {

    private TextView tvShow;

    private CountdownCallback countdownCallback;

    private boolean isSecond = true;

    private int countdownTime;

    private int f5789e;

    private Handler runCountTimerHandler = new RunCountTimerHandler();

    private Runnable f5791g = new C1854b();

    private Runnable f5792h = new C1855c();

    class RunCountTimerHandler extends Handler {
        RunCountTimerHandler() {
        }

        @Override
        public void handleMessage(@NonNull Message message) {
            super.handleMessage(message);
            int i = message.arg1;
            StringBuilder sb = new StringBuilder();
            sb.append("------");
            sb.append(i);
            LogUtils.d(sb.toString());
            int i2 = message.what;
            if (i2 == 1) {
                RunCountTimer.this.m7980p(i);
                RunCountTimer.this.m7976i(1000);
            } else if (i2 == 2) {
                RunCountTimer.this.m7975h();
            }
        }
    }

    class C1854b implements Runnable {
        C1854b() {
        }

        @Override
        public void run() {
            RunCountTimer.this.m7978k();
        }
    }

    /* renamed from: com.crrepa.band.my.view.component.b$c */
    /* compiled from: RunCountTimer */
    class C1855c implements Runnable {
        C1855c() {
        }

        @Override
        public void run() {
            RunCountTimer.this.m7981q();
            RunCountTimer.this.m7977j(1000);
        }
    }

    public interface CountdownCallback {
        void onComplete();
    }

    public RunCountTimer(int i) {
        this.countdownTime = i;
    }

    public void m7975h() {
        LogUtils.d("onFinish");
        this.tvShow.setVisibility(View.GONE);
        this.countdownCallback.onComplete();
    }

    public void m7976i(long j) {
        int i = (int) (((long) this.f5789e) - (j / 1000));
        this.f5789e = i;
        if (i > 0) {
            this.runCountTimerHandler.postDelayed(this.f5791g, j);
        } else if (this.isSecond) {
            this.runCountTimerHandler.postDelayed(this.f5792h, j);
        } else {
            m7977j(j);
        }
    }

    public void m7977j(long j) {
        Message obtainMessage = this.runCountTimerHandler.obtainMessage();
        obtainMessage.what = 2;
        this.runCountTimerHandler.sendMessageDelayed(obtainMessage, j);
    }

    public void m7978k() {
        Message obtainMessage = this.runCountTimerHandler.obtainMessage();
        obtainMessage.what = 1;
        obtainMessage.arg1 = this.f5789e;
        this.runCountTimerHandler.sendMessage(obtainMessage);
    }

    private void m7979l(TextView textView) {
        textView.setVisibility(View.VISIBLE);
        AnimationSet animationSet = new AnimationSet(false);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        alphaAnimation.setDuration(1000);
        animationSet.addAnimation(alphaAnimation);
        ScaleAnimation scaleAnimation = new ScaleAnimation(0.5f, 1.5f, 0.5f, 1.5f, 1, 0.5f, 1, 0.5f);
        scaleAnimation.setDuration(1000);
        animationSet.addAnimation(scaleAnimation);
        textView.startAnimation(animationSet);
    }

    public void m7980p(int i) {
        this.tvShow.setText(String.valueOf(i));
        m7979l(this.tvShow);
    }

    public void m7981q() {
        this.tvShow.setText(R.string.go);
        m7979l(this.tvShow);
    }

    public void mo18904g() {
        this.runCountTimerHandler.removeCallbacks(this.f5791g);
        this.runCountTimerHandler.removeCallbacks(this.f5792h);
        this.runCountTimerHandler.removeMessages(1);
        this.runCountTimerHandler.removeMessages(2);
    }

    public RunCountTimer setCountdownCallnack(CountdownCallback dVar) {
        this.countdownCallback = dVar;
        return this;
    }

    public RunCountTimer isSecond(boolean z) {
        this.isSecond = z;
        return this;
    }

    public RunCountTimer showTextView(TextView textView) {
        this.tvShow = textView;
        return this;
    }

    public RunCountTimer mo18908r() {
        this.f5789e = this.countdownTime;
        m7976i(0);
        return this;
    }
}
